package com.guli.coupon.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.guli.common.vo.CouponVo;
import com.guli.coupon.entity.CouponEntity;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.guli.coupon.entity.CouponSpuCategoryRelationEntity;
import com.guli.coupon.service.CouponSpuCategoryRelationService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;


/**
 * 优惠券与分类关联
 * @author zzb
 * @email 1626131069@qq.com
 * @date 2023-11-21 15:59:18
 */
@RestController
@RequestMapping("coupon/relatecategory")
public class CouponSpuCategoryRelationController {
    @Autowired
    private CouponSpuCategoryRelationService couponSpuCategoryRelationService;

    @GetMapping("/{categoryId}")
    @ApiOperation(value = "根据category_id查询关联的优惠卷")
    public R getCouponsRelateCategoryId(@PathVariable Long categoryId) {
        List<CouponVo> couponVos = couponSpuCategoryRelationService.getCouponsRelateCategoryId(categoryId);
        return R.ok().put("data", couponVos);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = couponSpuCategoryRelationService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        CouponSpuCategoryRelationEntity couponSpuCategoryRelation = couponSpuCategoryRelationService.getById(id);
        return R.ok().put("couponSpuCategoryRelation", couponSpuCategoryRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CouponSpuCategoryRelationEntity couponSpuCategoryRelation) {
        couponSpuCategoryRelationService.save(couponSpuCategoryRelation);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CouponSpuCategoryRelationEntity couponSpuCategoryRelation) {
        couponSpuCategoryRelationService.updateById(couponSpuCategoryRelation);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        couponSpuCategoryRelationService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
